package slicex

import "errors"

func Add[T any](src []T, element T, index int) ([]T, error) {
	l := len(src)
	if index < 0 || l <= index {
		return nil, errors.New("下标超出范围")
	}
	var zero T
	src = append(src, zero)

	for i := l; i > index; i-- {
		src[i] = src[i-1]
	}
	src[index] = element
	return src, nil
}
